<?
  require_once("connection.php");
  error_reporting(0);
?>
<html>
<head>
<script>
//-----------------------------------------------------------------------------
function exercise_slide_browse(exercise_id){
    formfield = jQuery('#upload_image').attr('name');
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    document.getElementById("update"+exercise_id).disabled = false;
}
//-----------------------------------------------------------------------------
function exercise_additional_browse(exercise_id){
    formfield = jQuery('#upload_image').attr('name');
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    document.getElementById("update_"+exercise_id).disabled = false;
}
//-----------------------------------------------------------------------------
function exercise_file_browse(exercise_id){
    formfield = jQuery('#upload_image').attr('name');
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    document.getElementById("update_file"+exercise_id).disabled = false;
}
//-----------------------------------------------------------------------------
function exercise_solution_browse(exercise_id){
    formfield = jQuery('#upload_image').attr('name');
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    document.getElementById("update_solution"+exercise_id).disabled = false;
}

</script>
</head>
<body>

  <div style="margin-left:300px;font-size:18;font-familyt:Arial">Exercises</div>
  <table width="100%">
    <tbody>
      <tr>
        <td>
          <a href="#" style="text-decoration:none;" onclick="add_exercise(0,0);return false;">
            <font size='2' color='blue'>
              Add new exercise
      	    </font>
  	  	  </a>
  	    </td>
  	  </tr>
    </tbody>
  </table>
  <br>

  <?
    if(isset($_POST["course_id"]))
      $course_id=$_POST["course_id"];
    else
      $course_id=0;

    $query = "select * from g_courses;";
    $result = @mysql_query($query);
    
	    echo "<select id='course' onchange='c_e_change(this);return false;'>";
	    if($course_id==0)
	      echo "<option value='0' selected>All Courses</option>";
	    else
          echo "<option value='0'>All Courses</option>";
	    while($row=@mysql_fetch_array($result)){
          if($course_id==$row["course_id"])
            echo "<option value='".$row["course_id"]."' selected>".$row["name"]." - ".$row["year"]." ".$row["semester"]."</option>";
          else
            echo "<option value='".$row["course_id"]."'>".$row["name"]." - ".$row["year"]." ".$row["semester"]."</option>";
	    }
	    echo "</select>";


    if($course_id!=0)
      $query = "select * from g_exercises t1, g_courses t2 where t1.course_id=t2.course_id and t1.course_id=".$_POST["course_id"]." order by t1.date;";
    else
      $query = "select * from g_exercises t1, g_courses t2 where t1.course_id=t2.course_id order by t1.date;";
    $result = @mysql_query($query);
    
    $row_number = @mysql_num_rows($result);
    
    echo " Rows: ".$row_number;

    if($row_number>0){
	    echo "<table class='tbl_2'><tbody>";
	    echo "<tr class='inside'>";
	    echo "<th>&nbsp;</th>";
	    echo "<th>&nbsp;</th>";
	    //echo "<th><a href='#' onclick='return false;display_table(3,1);return false;'>exercise_id</a></th>";
	    //echo "<th><a href='#' onclick='return false;display_table(3,2);return false;'>seq_number</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(3,3);return false;'>date</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(3,4);return false;'>file</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(3,5);return false;'>description</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(3,6);return false;'>solution</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(3,7);return false;'>deadline</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(3,8);return false;'>slide</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(3,9);return false;'>additional</a></th>";
	    echo "<th><a href='#' onclick='return false;display_table(3,10);return false;'>course_name</a></th>";
	    echo "</tr>";
	    while($row = @mysql_fetch_array($result)){
	        //echo "<tr class='inside' id='OnMouseTr".$row[0]."' style='background:#EAF7EB' onmouseover='mouse_over(".$row[0].");return false;' onmouseout='mouse_out(".$row[0].");return false;'>";
	        echo "<tr class='inside' id='OnMouseTr".$row[0]."' style='background:#EAF7EB' >";
	        echo "<td><a href='#' id='".$row[0]."' onclick='delete_exercise(".$row[0]."); return false;'><img border='0' alt='Delete' src='../wp-content/plugins/course_management/images/delete.png'/></a></td>";
	        echo "<td><a href='#' id='".$row[0]."' onclick='add_exercise(1,".$row[0]."); return false;'><img border='0' alt='Edit' src='../wp-content/plugins/course_management/images/edit.png'/></a></td>";
            //echo "<td>".$row["exercise_id"]."</td>";
	        //echo "<td>".$row["seq_num"]."</td>";
	        echo "<td>".$row["date"]."</td>";
	        if($row["file"]!="none")
	          echo "<td><a href='".$row["file"]."'>file</a> <input type='button' value='...' onclick='exercise_file_browse(".$row["exercise_id"].")'/><button id='update_file".$row["exercise_id"]."' onclick='exercise_file(".$row["exercise_id"].");' disabled>Upd</button></td>";
	        else
              echo "<td>no <input type='button' value='...' onclick='exercise_file_browse(".$row["exercise_id"].")'/><button id='update_file".$row["exercise_id"]."' onclick='exercise_file(".$row["exercise_id"].");' disabled>Upd</button></td>";
	        echo "<td>".$row["description"]."</td>";
	        if($row["solution"]!="none")
	          echo "<td><a href='".$row["solution"]."'>solut</a> <input type='button' value='...' onclick='exercise_solution_browse(".$row["exercise_id"].")'/><button id='update_solution".$row["exercise_id"]."' onclick='exercise_solution(".$row["exercise_id"].");' disabled>Upd</button></td>";
	        else
              echo "<td>none <input type='button' value='...' onclick='exercise_solution_browse(".$row["exercise_id"].")'/><button id='update_solution".$row["exercise_id"]."' onclick='exercise_solution(".$row["exercise_id"].");' disabled>Upd</button></td>";
	        echo "<td>".$row["deadline"]."</td>";
	        if($row["slide"]!="none")
	          echo "<td><a href='".$row["slide"]."'>slide</a> <input type='button' value='...' onclick='exercise_slide_browse(".$row["exercise_id"].")'/><button id='update".$row["exercise_id"]."' onclick='exercise_slide(".$row["exercise_id"].");' disabled>Upd</button></td>";
	        else
              echo "<td>none <input type='button' value='...' onclick='exercise_slide_browse(".$row["exercise_id"].")'/><button id='update".$row["exercise_id"]."' onclick='exercise_slide(".$row["exercise_id"].");' disabled>Upd</button></td>";
            if($row["additional"]!="none")
              echo "<td><a href='".$row["additional"]."'>addit</a> <input type='button' value='...' onclick='exercise_additional_browse(".$row["exercise_id"].")'/><button id='update_".$row["exercise_id"]."' onclick='exercise_additional(".$row["exercise_id"].");' disabled>Upd</button></td>";
            else
              echo "<td>none <input type='button' value='...' onclick='exercise_additional_browse(".$row["exercise_id"].")'/><button id='update_".$row["exercise_id"]."' onclick='exercise_additional(".$row["exercise_id"].");' disabled>Upd</button></td>";
	        echo "<td>".$row["name"]." - ".$row["year"]." ".$row["semester"]."</td>";
	        echo "</tr>";
	    }
	echo "</tbody></table>";
	}
	else{
        die("<br>There are no exercises!!!");
        exit;
	}
  ?>

</body>

</html>
